<template>
	<view class="container">
		<uni-forms ref="flowForm" class="form" label-width="120">
			<uni-forms-item label="资产分类" class="form-item">
					<view class="uni-input">{{info.cateName}}</view>
			</uni-forms-item>
			<uni-forms-item label="资产编码" class="form-item">
					<view class="uni-input">{{info.num}}</view>
			</uni-forms-item>
			<uni-forms-item label="生产厂商" class="form-item">
					<view class="uni-input">{{info.orgName}}</view>
			</uni-forms-item>
			<uni-forms-item label="型号" class="form-item">
					<view class="uni-input">{{info.modelName}}</view>
			</uni-forms-item>
			<uni-forms-item label="图例" class="form-item">
				<view class="uni-input" @click="previewImgs" v-if="imageList">
					<image style="width: 200px; height: 200px; background-color: #eeeeee;" 
					mode="aspectFit" :src="imageList[0]"></image>
				</view>
			</uni-forms-item>
			<uni-forms-item label="当前价值" class="form-item">
					<view class="uni-input">{{info.price}}</view>
			</uni-forms-item>
			<uni-forms-item label="购买日期" class="form-item">
					<view class="uni-input">{{info.buyTime}}</view>
			</uni-forms-item>
			<uni-forms-item label="所在仓库" class="form-item">
					<view class="uni-input">{{info.houseName}}</view>
			</uni-forms-item>
			<uni-forms-item label="是否在库" class="form-item">
					<view class="uni-input">{{dictTag('sys_yes_no', info.inStore)}}</view>
			</uni-forms-item>
			<uni-forms-item label="归属部门" class="form-item">
					<view class="uni-input">{{info.deptName}}</view>
			</uni-forms-item>
			<uni-forms-item label="是否在用" class="form-item">
					<view class="uni-input">{{dictTag('sys_yes_no', info.isUse)}}</view>
			</uni-forms-item>
			<uni-forms-item label="当前使用人" class="form-item" v-if="info.isUse == 'Y'">
					<view class="uni-input">{{info.userName}}</view>
			</uni-forms-item>
			<uni-forms-item label="当前状态" class="form-item">
					<view class="uni-input">{{assetStatus}}</view>
			</uni-forms-item>
		</uni-forms>
		<button type="primary" v-if="info.inStore == 'Y'" @click="handleFLow">创建工单</button>
	</view>
</template>


<script>
	import { getInfo} from '@/api/asset.js'
	import {getDicts} from '@/api/sys.js'
	import {selectFlowType	} from '@/api/flow.js'
	export default {
		data() {
			return {
				info: { },
				actionItems: [],
				typeList: [],
				dictOptions: {}
			}
		},
		onLoad() {
			getInfo(this.$route.query.id).then(response => {
				this.info = response.data;
			})
			getDicts('sys_yes_no').then(response => {
				this.dictOptions['sys_yes_no'] = response.data;
			})
			getDicts('asset_status').then(response => {
				this.dictOptions['asset_status'] = response.data;
			})
			selectFlowType({ status: '1' }).then(response => {
				for(let i=0;i<response.data.length;i++){
					if(response.data[i].code == 'purchase'){
						continue;
					}
					this.typeList.push(response.data[i]);
					this.actionItems.push(response.data[i].name);
				}
			})
		},
		computed: {
			imageList() {
				if(!this.info.imgs){
					return null;
				}else { 
					return this.info.imgs.split(';');
				}
			},
			assetName() {
				if(!this.formData.assetId){
					return '未选择';
				}else { 
					return this.assetList[this.assetIndex].num + ' (' + this.assetList[this.assetIndex].cateName + ')';
				}
			},
			assetStatus() {
				if(this.info.status === undefined){
					return '';
				}
				return this.dictTag('asset_status', this.info.status);
			}
		},
		methods: {
			dictTag(dictType, dictValue) {
				if(!this.dictOptions[dictType]){
					return '';
				}
				for(let i=0;i<this.dictOptions[dictType].length;i++){
					let dict = this.dictOptions[dictType][i];
					if(dict.dictValue == dictValue){
						return dict.dictLabel;
					}
				}
			},
			previewImgs() {
				uni.previewImage({
					urls: this.imageList
				});
			},
			handleFLow() {
				let that = this;
				uni.showActionSheet({
					itemList: this.actionItems,
					success: function (res) {
						that.$tab.navigateTo('/pages/flow/create?typeId='+that.typeList[res.tapIndex].id+'&assetId='+that.info.id);
					},
					fail: function (res) {
						console.log(res.errMsg);
					}
				});
			},
		}
	}
</script>

<style>
	.form {
		padding: 15px;
		background-color: #fff;
	}
	.button-group {
		margin-top: 15px;
		display: flex;
		justify-content: space-around;
	}

	.form-item {
		display: flex;
		align-items: center;
		place-items: center;
	}

	.button {
		display: flex;
		align-items: center;
		height: 35px;
		margin-left: 10px;
	}
</style>